package com.jyf.redis.common.model;

/**
 * 通用的返回类
 * @author jyf
 * @time 2020/11/9 20:03
 */
public final class Result<T> {

    //200代表成功，400代表失败
    private Integer code;//状态码

    private String status;//状态码对应的信息

    private String message;//返回的提示信息

    private T data; //返回的数据


    public static <T> Result<T> success(String message) {
        return new Result<>(200,"处理成功！", message);
    }
    public static <T> Result<T> success(String message, T data) {
        return new Result<>(200,"处理成功！", message, data);
    }

    public static <T> Result<T> success(Integer code,String message, T data) {
        return new Result<>(code,"处理成功！", message, data);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(400,"处理失败！", message);
    }
    public static <T> Result<T> fail(String message, T data) {
        return new Result<>(400,"处理失败！", message, data);
    }

    public static <T> Result<T> fail(Integer code,String message,T data){
        return new Result<>(code,"处理失败",message,data);
    }

    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Object getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }


    private Result(Integer code, String status, String message,T data) {
        this.code = code;
        this.status = status;
        this.message = message;
        this.data = data;
    }
    private Result(Integer code, String status, String message) {
        this.code = code;
        this.status = status;
        this.message = message;
    }

    private Result() {
    }

    @Override
    public String toString() {
        return "Result [code=" + code + ", status=" + status + ", message=" + message
                + ", data=" + data + "]";
    }



}
